package com.yds.ydsdatasetbackend.model.vo;

import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.yds.ydsdatasetbackend.model.entity.File;
import com.yds.ydsdatasetbackend.model.entity.FileTrain;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * 文件训练脱敏
 * @TableName file_train
 */
@Data
public class FileTrainVO implements Serializable {
    /**
     * id
     */
    private Long id;

    /**
     * 训练模型
     */
    private String model;

    /**
     * 训练占比（单位百分比）
     */
    private Long trainRate;

    /**
     * 是否数据洗牌
     */
    private Integer isRefresh;

    /**
     * 训练简介，用于描述训练模型的用途
     */
    private String introduction;

    /**
     * 训练状态：成功/等待/错误/运行
     */
    private String trainStatus;

    /**
     * 筛选特征，列号JSON数组
     */
    private List<Long> selectFeatures;

    /**
     * 筛选目标，列号JSON数组
     */
    private List<Long> selectTargets;

    /**
     * 文件Id
     */
    private Long fileId;

    /**
     * 创建用户 id
     */
    private Long userId;

    /**
     * 训练结果（JSON格式）
     */
    private TrainResult trainResult;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 创建文件信息
     */
    private FileVO file;

    /**
     * 创建用户信息
     */
    private UserVO user;

    private static final long serialVersionUID = 1L;

    /**
     * 封装类转对象
     */
    public static FileTrain voToObj(FileTrainVO fileTrainVO) {
        if (fileTrainVO == null) {
            return null;
        }
        FileTrain fileTrain = new FileTrain();
        BeanUtils.copyProperties(fileTrainVO, fileTrain);
        // 类型不同，需要转换
        fileTrain.setSelectFeatures(JSONUtil.toJsonStr(fileTrainVO.getSelectFeatures()));
        fileTrain.setSelectTargets(JSONUtil.toJsonStr(fileTrainVO.getSelectTargets()));
        fileTrain.setTrainResult(JSONUtil.toJsonStr(fileTrainVO.getTrainResult()));
        return fileTrain;
    }

    /**
     * 对象转封装类
     */
    public static FileTrainVO objToVo(FileTrain fileTrain) {
        if (fileTrain == null) {
            return null;
        }
        FileTrainVO fileTrainVO = new FileTrainVO();
        BeanUtils.copyProperties(fileTrain, fileTrainVO);
        // 类型不同，需要转换
        fileTrainVO.setSelectFeatures(JSONUtil.toList(fileTrain.getSelectFeatures(), Long.class));
        fileTrainVO.setSelectTargets(JSONUtil.toList(fileTrain.getSelectTargets(), Long.class));
        fileTrainVO.setTrainResult(JSONUtil.toBean(fileTrain.getTrainResult(), TrainResult.class));
        return fileTrainVO;
    }
}